using UnityEngine;
using UnityEditor;

public class ExportAssetBundles {
	[MenuItem("Assets/Build AssetBundle From Selection - Track dependencies")]
	static void ExportResource () {
		
		// Bring up save panel
		string path = EditorUtility.SaveFilePanel ("Save Resource", "", "New Resource", "unity3d");
		
		if (path.Length != 0) {
			// Build the resource file from the active selection.
			Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
			BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets);
			Selection.objects = selection;
		}
	}
	
	[MenuItem("Assets/Build AssetBundle From Selection - No dependency tracking")]
	static void ExportResourceNoTrack () {
		
		// Bring up save panel
		string path = EditorUtility.SaveFilePanel ("Save Resource", "", "New Resource", "unity3d");
		
		if (path.Length != 0) {
			// Build the resource file from the active selection.
			BuildPipeline.BuildAssetBundle(Selection.activeObject, Selection.objects, path);
		}
	}
	
	[MenuItem("Assets/Build AssetBundle From Selection - Track dependencies iPhone")]
	static void ExportAssetBundleIOSComplete() {
		// Bring up save panel
		string path = EditorUtility.SaveFilePanel("Save Resource", "", "New Resource", "unity3d");
		if (path.Length != 0) {
			// Build the resource file from the active selection.
			//
			Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
			//
			BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets, BuildTarget.iPhone);
			Selection.objects = selection;
			//
		}
	}
	
	[MenuItem("Assets/Build AssetBundle From Selection - Track dependencies Android")]
	static void ExportAssetBundleAndroidComplete() {
		// Bring up save panel
		string path = EditorUtility.SaveFilePanel("Save Resource", "", "New Resource", "unity3d");
		if (path.Length != 0) {
			// Build the resource file from the active selection.
			//
			Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
			//
			BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets, BuildTarget.Android);
			Selection.objects = selection;
			//
		}
	}
}